package com.iams.manage.instener;

import com.iams.common.utils.spring.SpringUtils;
import com.iams.manage.domain.Archive;
import com.iams.manage.domain.ArchiveDestroyApproval;
import com.iams.manage.mapper.ArchiveDestroyApprovalMapper;
import com.iams.manage.service.IArchiveService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

public class ArchiveDestroyEndListener implements ExecutionListener {

    @Override
    public void notify(DelegateExecution delegateExecution) {


        String businessKey = delegateExecution.getProcessInstanceBusinessKey();
        ArchiveDestroyApprovalMapper archiveDestroyApprovalMapper = SpringUtils.getBean(ArchiveDestroyApprovalMapper.class);
        ArchiveDestroyApproval archiveDestroyApproval = archiveDestroyApprovalMapper.selectArchiveDestroyApprovalByBusinessKey(businessKey);

        IArchiveService archiveService = SpringUtils.getBean(IArchiveService.class);
        Archive archive = archiveService.selectArchiveById(archiveDestroyApproval.getArchiveId());
        archive.setStatus("Destroyed");
        archiveService.updateArchive(archive);
    }
}
